import React from "react";
import { Link, Routes, Route, Outlet } from "react-router-dom";

const Classify = () => {
  return <div>分类页面</div>;
};
const Hot = () => {
  return <div>热销页面</div>;
};

const Home = () => {
  return (
    <>
      <div>这是首页</div>
      <ul>
        <li>
          <Link to="/home/classify">分类页</Link>
        </li>
        <li>
          <Link to="/home/hot">热销页</Link>
        </li>
      </ul>

      <hr />

      {/* 相当于vue的router-view */}
      <Outlet />
    </>
  );
};
const About = () => {
  return <div>这是关于页</div>;
};

const App = () => {
  return (
    <>
      <h2>嵌套路由</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
      </ul>
      <ul>
        <li>
          <Link to="/about">关于页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        {/* Route组件可以进行嵌套，可以和Outlet的组件配合实现嵌套路由 */}
        <Route path="/home" element={<Home />}>
          <Route path="/home/classify" element={<Classify />}></Route>
          <Route path="/home/hot" element={<Hot />}></Route>
        </Route>
        <Route path="/about" element={<About />}></Route>
      </Routes>
    </>
  );
};

export default App;
